#!/usr/bin/env bash

echo -e "\033[34m--------------------wsgi process--------------------\033[0m"

# 查找并关闭旧的 screen
screen_id=$(screen -ls | grep asms_test | awk '{print $1}')
if [ -n "$screen_id" ]; then
    echo -e "\n--------------------going to close old screen--------------------"
    screen -X -S $screen_id quit
    sleep 0.5
fi

# 查找并关闭旧的 uwsgi 进程
echo -e '\n--------------------going to close old uwsgi process--------------------'
ps -ef | grep asms_uwsgi.ini | grep -v grep | awk '{print $2}' | xargs kill -9
sleep 0.5

echo -e '\n----------check if the kill action is correct----------'

# 启动新的 screen
screen -dmS asms_test bash -c "/envs/ecs_project/bin/uwsgi --ini asms_uwsgi.ini"
sleep 1

echo -e '\n\033[42;1m----------------------started...----------------------\033[0m'

# 查看新的 uwsgi 进程
ps -ef | grep asms_uwsgi.ini | grep -v grep

